home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / airbustr.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  6KB  |  274 lines

  1. /**************************************************************************
  2.  
  3.                                 Air Buster
  4.                             (C) 1990  Kaneko
  5.  
  6.                     driver by Luca Elia (eliavit@unina.it)
  7.  
  8. [Screen]
  9.      Size:                256 x 256
  10.     Colors:                256 x 3
  11.     Color Space:        32R x 32G x 32B
  12.  
  13. [Scrolling layers]
  14.     Number:                2
  15.     Size:                512 x 512
  16.     Scrolling:            X,Y
  17.     Tiles Size:            16 x 16
  18.     Tiles Number:        0x1000
  19.     Colors:                256 x 2    (0-511)
  20.     Format:
  21.                 Offset:        0x400    0x000
  22.                 Bit:        fedc---- --------    Color
  23.                             ----ba98 76543210    Code
  24.  
  25. [Sprites]
  26.     On Screen:            256 x 2
  27.     In ROM:                0x2000
  28.     Colors:                256        (512-767)
  29.     Format:                See Below
  30.  
  31.  
  32. **************************************************************************/
  33. #include "driver.h"
  34.  
  35. static struct tilemap *bg_tilemap,*fg_tilemap;
  36.  
  37. /* Variables that drivers has access to */
  38. unsigned char *airbustr_bgram, *airbustr_fgram;
  39.  
  40. /* Variables defined in drivers */
  41. extern unsigned char *spriteram;
  42. extern int flipscreen;
  43.  
  44.  
  45. /***************************************************************************
  46.  
  47.   Callbacks for the TileMap code
  48.  
  49. ***************************************************************************/
  50.  
  51. static void get_fg_tile_info(int tile_index)
  52. {
  53.     unsigned char attr = airbustr_fgram[tile_index + 0x400];
  54.     SET_TILE_INFO(    0,
  55.                     airbustr_fgram[tile_index] + ((attr & 0x0f) << 8),
  56.                     (attr >> 4) + 0);
  57. }
  58.  
  59. static void get_bg_tile_info(int tile_index)
  60. {
  61.     unsigned char attr = airbustr_bgram[tile_index + 0x400];
  62.     SET_TILE_INFO(    0,
  63.                     airbustr_bgram[tile_index] + ((attr & 0x0f) << 8),
  64.                     (attr >> 4) + 16);
  65. }
  66.  
  67.  
  68.  
  69. int airbustr_vh_start(void)
  70. {
  71.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
  72.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,     16,16,32,32);
  73.  
  74.     if (!fg_tilemap || !bg_tilemap)
  75.         return 1;
  76.  
  77.     fg_tilemap->transparent_pen = 0;
  78.  
  79.     return 0;
  80. }
  81.  
  82.  
  83. WRITE_HANDLER( airbustr_fgram_w )
  84. {
  85.     if (airbustr_fgram[offset] != data)
  86.     {
  87.         airbustr_fgram[offset] = data;
  88.         tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
  89.     }
  90. }
  91.  
  92. WRITE_HANDLER( airbustr_bgram_w )
  93. {
  94.     if (airbustr_bgram[offset] != data)
  95.     {
  96.         airbustr_bgram[offset] = data;
  97.         tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
  98.     }
  99. }
  100.  
  101.  
  102. /*    Scroll Registers
  103.  
  104.     Port:
  105.     4        Bg Y scroll, low 8 bits
  106.     6        Bg X scroll, low 8 bits
  107.     8        Fg Y scroll, low 8 bits
  108.     A        Fg X scroll, low 8 bits
  109.  
  110.     C        3        2        1        0        <-Bit
  111.             Bg Y    Bg X    Fg Y    Fg X    <-Scroll High Bits (complemented!)
  112. */
  113.  
  114. WRITE_HANDLER( airbustr_scrollregs_w )
  115. {
  116. static int bg_scrollx, bg_scrolly, fg_scrollx, fg_scrolly, highbits;
  117. int xoffs, yoffs;
  118.  
  119.     if (flipscreen)    {    xoffs = -0x06a;        yoffs = -0x1ff;}
  120.     else            {    xoffs = -0x094;        yoffs = -0x100;}
  121.  
  122.     switch (offset)        // offset 0 <-> port 4
  123.     {
  124.         case 0x00:    fg_scrolly =  data;    break;    // low 8 bits
  125.         case 0x02:    fg_scrollx =  data;    break;
  126.         case 0x04:    bg_scrolly =  data;    break;
  127.         case 0x06:    bg_scrollx =  data;    break;
  128.         case 0x08:    highbits   = ~data;    break;    // complemented high bits
  129.  
  130.         default:    logerror("CPU #2 - port %02X written with %02X - PC = %04X\n", offset, data, cpu_get_pc());
  131.     }
  132.  
  133.     tilemap_set_scrollx(bg_tilemap, 0, ((highbits << 6) & 0x100) + bg_scrollx + xoffs );
  134.     tilemap_set_scrolly(bg_tilemap, 0, ((highbits << 5) & 0x100) + bg_scrolly + yoffs );
  135.     tilemap_set_scrollx(fg_tilemap, 0, ((highbits << 8) & 0x100) + fg_scrollx + xoffs );
  136.     tilemap_set_scrolly(fg_tilemap, 0, ((highbits << 7) & 0x100) + fg_scrolly + yoffs );
  137. }
  138.  
  139.  
  140.  
  141. /*        Sprites
  142.  
  143. Offset:                    Values:
  144.  
  145. 000-0ff                    ?
  146. 100-1ff                    ?
  147. 200-2ff                    ?
  148.  
  149. 300-3ff        7654----    Color Code
  150.             ----3---    ?
  151.             -----2--    Multi Sprite
  152.             ------1-    Y Position High Bit
  153.             -------0    X Position High Bit
  154.  
  155. 400-4ff                    X Position Low 8 Bits
  156. 500-5ff                    Y Position Low 8 Bits
  157. 600-6ff                    Code Low 8 Bits
  158.  
  159. 700-7ff        7-------    Flip X
  160.             -6------    Flip Y
  161.             --5-----    ?
  162.             ---43217    Code High Bits
  163.  
  164. */
  165.  
  166. static void draw_sprites(struct osd_bitmap *bitmap)
  167. {
  168. int i, offs;
  169.  
  170.     /* Let's draw the sprites */
  171.     for (i = 0 ; i < 2 ; i++)
  172.     {
  173.         unsigned char *ram = &spriteram[i * 0x800];
  174.         int sx = 0;
  175.         int sy = 0;
  176.  
  177.         for ( offs = 0 ; offs < 0x100 ; offs++)
  178.         {
  179.             int attr    =    ram[offs + 0x300];
  180.             int x        =    ram[offs + 0x400] - ((attr << 8) & 0x100);
  181.             int y        =    ram[offs + 0x500] - ((attr << 7) & 0x100);
  182.  
  183.             int gfx        =    ram[offs + 0x700];
  184.             int code    =    ram[offs + 0x600] + ((gfx & 0x1f) << 8);
  185.             int flipx    =    gfx & 0x80;
  186.             int flipy    =    gfx & 0x40;
  187.  
  188.             /* multi sprite */
  189.             if (attr & 0x04)    { sx += x;        sy += y;}
  190.             else                { sx  = x;        sy  = y;}
  191.  
  192.             if (flipscreen)
  193.             {
  194.                 sx = 240 - sx;        sy = 240 - sy;
  195.                 flipx = !flipx;        flipy = !flipy;
  196.             }
  197.  
  198.             drawgfx(bitmap,Machine->gfx[1],
  199.                     code,
  200.                     attr >> 4,
  201.                     flipx, flipy,
  202.                     sx,sy,
  203.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  204.  
  205.             /* let's get back to normal to support multi sprites */
  206.             if (flipscreen)    {sx = 240 - sx;        sy = 240 - sy;}
  207.  
  208.         }
  209.     }
  210.  
  211. }
  212.  
  213.  
  214. void airbustr_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  215. {
  216. unsigned char *ram;
  217. int i, offs;
  218.  
  219. #if 0
  220. /*
  221.     Let's show some of the unknown bits:
  222.     bankswitch reg cpu 0, 1, 2 [& 0xf8!] and sub cpu port 28
  223. */
  224.  
  225.     if (keyboard_pressed(KEYCODE_Z))
  226.     {
  227.     char buf[80];
  228.         sprintf(buf,"%02X %02X %02X %02X", u1,u2,u3,u4);
  229.         usrintf_showmessage(buf);
  230.     }
  231. #endif
  232.  
  233.     tilemap_update(ALL_TILEMAPS);
  234.  
  235. /* Palette Stuff */
  236.  
  237.     palette_init_used_colors();
  238.  
  239. #if 0
  240.     /* Scrolling Layers */
  241.     ram = &airbustr_bgram[0x000 + 0x400];    // color code
  242.     for ( offs = 0 ; offs < 0x100 ; offs++)
  243.     {
  244.         int color =    256 * 0 + (ram[offs] & 0xf0);
  245.         memset(&palette_used_colors[color],PALETTE_COLOR_USED,16);
  246.     }
  247.     ram = &airbustr_fgram[0x800 + 0x400];    // color code
  248.     for ( offs = 0 ; offs < 0x100 ; offs++)
  249.     {
  250.         int color =    256 * 1 + (ram[offs] & 0xf0);
  251.         memset(&palette_used_colors[color+1],PALETTE_COLOR_USED,16-1);
  252.     }
  253. #endif
  254.  
  255.     /* Sprites */
  256.     for (i = 0 ; i < 2 ; i++)
  257.     {
  258.         ram = &spriteram[i * 0x800 + 0x300];    // color code
  259.         for ( offs = 0 ; offs < 0x100 ; offs++)
  260.         {
  261.             int color = 256 * 2 + (ram[offs] & 0xf0);
  262.             memset(&palette_used_colors[color+1],PALETTE_COLOR_USED,16-1);
  263.         }
  264.     }
  265.  
  266.     if (palette_recalc())    tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  267.  
  268.     tilemap_render(ALL_TILEMAPS);
  269.  
  270.     tilemap_draw(bitmap,bg_tilemap,0);
  271.     tilemap_draw(bitmap,fg_tilemap,0);
  272.     draw_sprites(bitmap);
  273. }
  274.